/***********************************************************************
 * Module:  Question.java
 * Author:  DAC
 * Purpose: Defines the Class Question
 ***********************************************************************/
package com.group1.model;
import java.util.*;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid fdb5f0d7-5f50-4f43-8396-25db714b3c3e */
public class Question {
   /** @pdOid a67528f0-3b68-448c-8490-54fae1d5b8f1 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 4cbfeb3f-2f0b-4118-afc8-4be889b2fda6 */
   public Integer questionId;
   /** @pdOid 2f4bda41-fb47-4f21-b0f8-39224f52ed86 */
   public java.lang.String questionDesc;
   /** @pdOid cb7a6883-0923-4338-8e64-7b882c51b983 */
   public java.lang.String questionType;
   /** @pdOid 8d471e09-f915-44d8-8e01-660ebf7519e0 */
   public int questionLevel;
   
   /** @pdRoleInfo migr=no name=AnswerItem assc=answerItemsOfQuestions coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   private Set answerItem = new HashSet(0);
   /** @pdRoleInfo migr=no name=QuestionImage assc=figuresOfQuestions coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   private Set questionImage = new HashSet(0);
   /** @pdRoleInfo migr=no name=Topic assc=questionOfTopic coll=java.util.Collection impl=java.util.HashSet mult=0..* side=A */
   private Set TopicQuestionMapping = new HashSet(0);
   /** @pdRoleInfo migr=no name=Lecturer assc=creatorOfQuestions mult=0..1 side=A */
   public Lecturer lecturer;
   
   public static List<Question> getAllQuestion(Session session)
   {
	   Query query = session.createQuery("from Question");                
	   List <Question> list = query.list();
	   return list;
   }
   
   public static Question getQuestionByID(Integer questionID, Session session)
   {
	   return (Question) session.load(Question.class, questionID);
   }
   
   public static Set getQuestionByTopic(Integer topicID, Session session)
   {
	   Topic t = Topic.getTopicByID(topicID, session);
	   return t.getTopicQuestionMapping();
   }
   
   public static List<Question> getQuestionByLecturer(String lecturerID, Session session)
   {
	   Query query = session.createQuery("from Question where LECTURER_ID = '" + lecturerID +"'");                
	   List <Question> list = query.list();
	   return list;
   }
   
   /** @pdOid 612598e2-0c95-40e5-9dec-d8208b9bfb9e */
   public Integer getQuestionId() {
      return questionId;
   }
   
   /** @param newQuestionId
    * @pdOid 51bce8c2-4319-493d-b9aa-2ad947c782f3 */
   public void setQuestionId(Integer newQuestionId) {
      questionId = newQuestionId;
   }
   
   /** @pdOid 73713720-9933-4202-8756-6ea9b31af99e */
   public Question() {
      // TODO: implement
   }
   
   /** @pdOid f449dcf2-b047-4efa-9739-68fbc2b718fd */
   public java.lang.String getQuestionDesc() {
      return questionDesc;
   }
   
   /** @param newQuestionDesc
    * @pdOid cfa63a7a-1d9e-4fb0-a91d-72d95d3a1475 */
   public void setQuestionDesc(java.lang.String newQuestionDesc) {
      questionDesc = newQuestionDesc;
   }
   
   /** @pdOid 03ef9809-2571-4284-a171-74c4691bf2aa */
   public java.lang.String getQuestionType() {
      return questionType;
   }
   
   /** @param newQuestionType
    * @pdOid 30aeed7c-0280-4021-94b9-c14dcaf0db77 */
   public void setQuestionType(java.lang.String newQuestionType) {
      questionType = newQuestionType;
   }
   
   /** @pdOid 3133d4dd-688c-4a5e-8493-01147541a0a8 */
   public int getQuestionLevel() {
      return questionLevel;
   }
   
   /** @param newQuestionLevel
    * @pdOid 0a6be800-ded5-4604-b952-5b4874204448 */
   public void setQuestionLevel(int newQuestionLevel) {
      questionLevel = newQuestionLevel;
   }
   
   public Set getAnswerItem() {
		return this.answerItem;
	}

	public void setAnswerItem(Set answerItem) {
		this.answerItem = answerItem;
	}
	
//   /** @pdGenerated default getter */
//   public java.util.Collection<AnswerItem> getAnswerItem() {
//      if (answerItem == null)
//         answerItem = new java.util.HashSet<AnswerItem>();
//      return answerItem;
//   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorAnswerItem() {
      if (answerItem == null)
         answerItem = new java.util.HashSet<AnswerItem>();
      return answerItem.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newAnswerItem */
//   public void setAnswerItem(java.util.Collection<AnswerItem> newAnswerItem) {
//      removeAllAnswerItem();
//      for (java.util.Iterator iter = newAnswerItem.iterator(); iter.hasNext();)
//         addAnswerItem((AnswerItem)iter.next());
//   }
   
   /** @pdGenerated default add
     * @param newAnswerItem */
   public void addAnswerItem(AnswerItem newAnswerItem) {
      if (newAnswerItem == null)
         return;
      if (this.answerItem == null)
         this.answerItem = new java.util.HashSet<AnswerItem>();
      if (!this.answerItem.contains(newAnswerItem))
      {
         this.answerItem.add(newAnswerItem);
         newAnswerItem.setQuestion(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldAnswerItem */
   public void removeAnswerItem(AnswerItem oldAnswerItem) {
      if (oldAnswerItem == null)
         return;
      if (this.answerItem != null)
         if (this.answerItem.contains(oldAnswerItem))
         {
            this.answerItem.remove(oldAnswerItem);
            oldAnswerItem.setQuestion((Question)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllAnswerItem() {
      if (answerItem != null)
      {
         AnswerItem oldAnswerItem;
         for (java.util.Iterator iter = getIteratorAnswerItem(); iter.hasNext();)
         {
            oldAnswerItem = (AnswerItem)iter.next();
            iter.remove();
            oldAnswerItem.setQuestion((Question)null);
         }
      }
   }
   
   public Set getQuestionImage() {
		return this.questionImage;
	}

	public void setQuestionImage(Set questionImage) {
		this.questionImage = questionImage;
	}
   
//   /** @pdGenerated default getter */
//   public java.util.Collection<QuestionImage> getQuestionImage() {
//      if (questionImage == null)
//         questionImage = new java.util.HashSet<QuestionImage>();
//      return questionImage;
//   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestionImage() {
      if (questionImage == null)
         questionImage = new java.util.HashSet<QuestionImage>();
      return questionImage.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newQuestionImage */
//   public void setQuestionImage(java.util.Collection<QuestionImage> newQuestionImage) {
//      removeAllQuestionImage();
//      for (java.util.Iterator iter = newQuestionImage.iterator(); iter.hasNext();)
//         addQuestionImage((QuestionImage)iter.next());
//   }
   
   /** @pdGenerated default add
     * @param newQuestionImage */
   public void addQuestionImage(QuestionImage newQuestionImage) {
      if (newQuestionImage == null)
         return;
      if (this.questionImage == null)
         this.questionImage = new java.util.HashSet<QuestionImage>();
      if (!this.questionImage.contains(newQuestionImage))
      {
         this.questionImage.add(newQuestionImage);
         newQuestionImage.setQuestion(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestionImage */
   public void removeQuestionImage(QuestionImage oldQuestionImage) {
      if (oldQuestionImage == null)
         return;
      if (this.questionImage != null)
         if (this.questionImage.contains(oldQuestionImage))
         {
            this.questionImage.remove(oldQuestionImage);
            oldQuestionImage.setQuestion((Question)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestionImage() {
      if (questionImage != null)
      {
         QuestionImage oldQuestionImage;
         for (java.util.Iterator iter = getIteratorQuestionImage(); iter.hasNext();)
         {
            oldQuestionImage = (QuestionImage)iter.next();
            iter.remove();
            oldQuestionImage.setQuestion((Question)null);
         }
      }
   }

	public Set getTopicQuestionMapping() {
		return this.TopicQuestionMapping;
	}

	public void setTopicQuestionMapping(Set TopicQuestionMapping) {
		this.TopicQuestionMapping = TopicQuestionMapping;
	}
   
//   /** @pdGenerated default getter */
//   public java.util.Collection<Topic> getTopicQuestionMapping() {
//      if (TopicQuestionMapping == null)
//         TopicQuestionMapping = new java.util.HashSet<Topic>();
//      return TopicQuestionMapping;
//   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTopicQuestionMapping() {
      if (TopicQuestionMapping == null)
         TopicQuestionMapping = new java.util.HashSet<Topic>();
      return TopicQuestionMapping.iterator();
   }
   
//   /** @pdGenerated default setter
//     * @param newTopicQuestionMapping */
//   public void setTopicQuestionMapping(java.util.Collection<Topic> newTopicQuestionMapping) {
//      removeAllTopicQuestionMapping();
//      for (java.util.Iterator iter = newTopicQuestionMapping.iterator(); iter.hasNext();)
//         addTopicQuestionMapping((Topic)iter.next());
//   }
   
   /** @pdGenerated default add
     * @param newTopic */
   public void addTopicQuestionMapping(Topic newTopic) {
      if (newTopic == null)
         return;
      if (this.TopicQuestionMapping == null)
         this.TopicQuestionMapping = new java.util.HashSet<Topic>();
      if (!this.TopicQuestionMapping.contains(newTopic))
      {
         this.TopicQuestionMapping.add(newTopic);
         newTopic.addTopicQuestionMapping(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTopic */
   public void removeTopicQuestionMapping(Topic oldTopic) {
      if (oldTopic == null)
         return;
      if (this.TopicQuestionMapping != null)
         if (this.TopicQuestionMapping.contains(oldTopic))
         {
            this.TopicQuestionMapping.remove(oldTopic);
            oldTopic.removeTopicQuestionMapping(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTopicQuestionMapping() {
      if (TopicQuestionMapping != null)
      {
         Topic oldTopic;
         for (java.util.Iterator iter = getIteratorTopicQuestionMapping(); iter.hasNext();)
         {
            oldTopic = (Topic)iter.next();
            iter.remove();
            oldTopic.removeTopicQuestionMapping(this);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Lecturer getLecturer() {
      return lecturer;
   }
   
   /** @pdGenerated default parent setter
     * @param newLecturer */
   public void setLecturer(Lecturer newLecturer) {
	   this.lecturer = newLecturer;
   }

}